package com.ruoyi.web.controller.paper;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.system.domain.QtTk;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.paper.domain.QtPaper;
import com.ruoyi.paper.service.IQtPaperService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * paperController
 * 
 * @author zqq
 * @date 2021-11-18
 */
@RestController
@RequestMapping("/paper/paper")
public class QtPaperController extends BaseController
{
    @Autowired
    private IQtPaperService qtPaperService;

    /**
     * 查询paper列表
     */
    @PreAuthorize("@ss.hasPermi('paper:paper:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtPaper qtPaper)
    {
        startPage();
        List<QtPaper> list = qtPaperService.selectQtPaperList(qtPaper);
        return getDataTable(list);
    }

    /**
     * 导出paper列表
     */
    @PreAuthorize("@ss.hasPermi('paper:paper:export')")
    @Log(title = "paper", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtPaper qtPaper)
    {
        List<QtPaper> list = qtPaperService.selectQtPaperList(qtPaper);
        ExcelUtil<QtPaper> util = new ExcelUtil<QtPaper>(QtPaper.class);
        return util.exportExcel(list, "paper数据");
    }

    /**
     * 获取paper详细信息
     */
    @PreAuthorize("@ss.hasPermi('paper:paper:query')")
    @GetMapping(value = "/{paperId}")
    public AjaxResult getInfo(@PathVariable("paperId") String paperId)
    {
        return AjaxResult.success(qtPaperService.selectQtPaperByPaperId(paperId));
    }

    /**
     * 新增paper
     */
    @PreAuthorize("@ss.hasPermi('paper:paper:add')")
    @Log(title = "paper", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtPaper qtPaper)
    {
        LoginUser user = getLoginUser();
        qtPaper.setUserId(user.getUserId().toString());
        return toAjax(qtPaperService.insertQtPaper(qtPaper));
    }
    @PreAuthorize("@ss.hasPermi('paper:paper:zujuan')")
    @Log(title = "zujuan", businessType = BusinessType.INSERT)
    @PostMapping("/zujuan")
    public AjaxResult zujuan(QtPaper qtPaper)
    {
        return toAjax(qtPaperService.zujuan(qtPaper));
    }

    /**
     * 修改paper
     */
    @PreAuthorize("@ss.hasPermi('paper:paper:edit')")
    @Log(title = "paper", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtPaper qtPaper)
    {
        return toAjax(qtPaperService.updateQtPaper(qtPaper));
    }

    /**
     * 删除paper
     */
    @PreAuthorize("@ss.hasPermi('paper:paper:remove')")
    @Log(title = "paper", businessType = BusinessType.DELETE)
	@DeleteMapping("/{paperIds}")
    public AjaxResult remove(@PathVariable String[] paperIds)
    {
        return toAjax(qtPaperService.deleteQtPaperByPaperIds(paperIds));
    }

    @GetMapping("/getTk")
    public List<QtTk> getTk(QtPaper qtPaper){
        return qtPaperService.getTk(qtPaper);
    }
}
